<template>
    <div class="setting-page">
        <div class="setting-page-center">
            <div class="setting-page-left">
                <div class="setting-nav">
                    <div class="setting-nav-title">信息设置</div>
                    <el-menu>
                        <el-menu-item
                                v-bind:class="activeIndex == index ? 'menu-checked' : ''"
                                v-for="(item, index) in infoList"
                                :key="index"
                                @click="doNav(item,index)">
                            <span slot="title">{{item.label}}</span>
                        </el-menu-item>
                    </el-menu>
                    <div class="setting-nav-title-middle">账号设置</div>
                    <el-menu>
                        <el-menu-item
                                v-bind:class="activeIndex == index+2 ? 'menu-checked' : ''"
                                v-for="(item, index) in navsList"
                                :key="index"
                                @click="doNav(item,index+2)">
                            <span slot="title">{{item.label}}</span>
                        </el-menu-item>
                    </el-menu>
                </div>
            </div>
            <div class="setting-page-rigth">
                <router-view></router-view>
            </div>
        </div>
    </div>
</template>

<script>
  import _subject from '../../assets/utils/subject'
  import * as _ from 'underscore'

  export default {
    name:'index-setting',
    data() {
      return {
        activeIndex: 0,
        infoList: [
          { label: '个人信息', to: '/setting/personal' },
          { label: '企业信息', to: '/setting/company' }
        ],
        navsList: [
          { label: '绑定账号', to: '/setting/binding' },
          { label: '修改密码', to: '/setting/password' }
        ],
        subscription: null
      }
    },
    mounted() {
      this.initSta()
    },
    methods: {
      initSta() {
        // if (this.$route.query.active != '') {
        //   this.activeIndex = this.$route.query.active
        //   console.log(this.activeIndex)
        // }
        //this.activeIndex = _g.getCache().sIndex
      },
      doNav(item, index) {
        this.activeIndex = index
        this.$router.push({ path: item.to })
      }
    },
    components: {},
    created() {
      let that = this;
      this.subscription = _subject.setting.subscribe({
        next: function(t) {
          console.log(t)
          that.activeIndex = t;
        }
      })
    },
    destroyed() {
      if (!_.isNull(this.subscription)) {
        this.subscription.unsubscribe()
      }
    }
  }
</script>

<style lang="scss" scoped>
</style>
